package com.travelsky.airchina.boarding.web.validator;

import org.springframework.util.StringUtils;
import org.springframework.validation.Errors;
import org.springframework.web.multipart.MultipartFile;

import com.travelsky.airchina.boarding.domain.News;
/**
 * 104856700
 * @author haichenwang
 *
 */
public class VideoValidator {
	public void validate(News video,MultipartFile videoFile, Errors errors) {
		if(!StringUtils.hasLength(video.getTitle())){
			errors.rejectValue("title", "required",new Object[]{"视频名称"}, "required");
		}
		if(videoFile!=null){
			if(video.getId()==null){
				if(!videoFile.getOriginalFilename().endsWith(".flv")){
					errors.rejectValue("videoPath", "videoFileUnformat",new Object[]{"视频文件"}, "请上传flv文件");
				}
				if(videoFile.getSize()>104856700){
					errors.rejectValue("videoPath", "tooBig",new Object[]{"视频文件"}, "内容太大,确保其小于100M");
				}
			}else{
				if(videoFile.getSize()>0){
					if(!videoFile.getOriginalFilename().endsWith(".flv")){
						errors.rejectValue("videoPath", "videoFileUnformat",new Object[]{"视频文件"}, "请上传flv文件");
					}
					if(videoFile.getSize()>104856700){
						errors.rejectValue("videoPath", "tooBig",new Object[]{"视频文件"}, "内容太大,确保其小于100M");
					}
				}
			}
		}else{
			if(video.getId()==null){
				errors.rejectValue("videoPath", "required","请选择视频文件");
			}
		}
	}
}
